export type RequestOptions = any;

// 定义接口，不负责实现
export interface Requestor {
  get(url: string, options: RequestOptions): Promise<Response>;
  // 略...
}

// 本模块的大部分功能都需要使用到requestor
let req: Requestor;
export function inject(requestor: Requestor) {
  req = requestor;
}
export function useRequestor() {
  return req;
}

// 创建一个可以重试的请求
export function createRetryRequestor(maxCount = 5) {
  const req = useRequestor();
  // 进一步配置req
  return req;
}

// 创建一个并发请求
export function createParallelRequestor(maxCount = 4) {
  const req = useRequestor();
  // 进一步配置req
  return req;
}

// 缓存
export function createCacheRequestor(options = {}) {
  const req = useRequestor();
  // 进一步的配置

  return req;
}
